package com.cloudpivot.project.crmprojectnew.controller;

import com.cloudpivot.project.crmprojectnew.pojo.contact.Contact;
import com.cloudpivot.project.crmprojectnew.pojo.contact.ContactList;
import com.cloudpivot.project.crmprojectnew.service.impl.ContactServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@Slf4j
@RequestMapping("/crmContact")
public class ContactController {

    @Autowired
    private ContactServiceImpl contactService;

    /**
     * 获取客户联系人信息
     * @param guid
     * @return
     */
    @GetMapping("getInfo")
    @ResponseBody
    public Contact getInfo(@RequestParam(value = "guid") String guid) {
        Contact contact = contactService.getContact(guid);
        return contact;
    }

    /**获取客户联系人信息列表
     *
     * @param userid
     * @param id
     * @param pageindex
     * @param pageSize
     * @return
     */
    @GetMapping("getInfos")
    @ResponseBody
    public ContactList getInfos(@RequestParam(value = "userid") String userid, @RequestParam(value = "id") String id, @RequestParam(value = "pageIndex") int pageindex, @RequestParam(value = "pageSize") int pageSize) {
        log.info("传入参数{}#{}#{}", id, pageindex, pageSize);
        if(!"".equals(id)){
            return contactService.getContacts(userid, id);
        }else{
            return contactService.getContacts(userid, pageindex, pageSize);
        }
    }
}
